package com.example.memurbac_service.dao;

import com.example.memurbac_service.pojo.Role;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
@Mapper
public interface RoleMapper {

    @Select("select * from t_role where role_status=0")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "role_name",column = "role_name"),
            @Result(property = "role_desc",column = "role_desc"),
            @Result(property = "role_status",column = "role_status"),
            @Result(property = "role_createtime",column = "role_createtime"),
            @Result(property = "role_modiftime",column = "role_modiftime"),
            @Result(property = "role_type",column = "role_type")
    })
    List<Role> SelectRole();

    @Select("select * from t_role where   role_name like '%${role_name}%'")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "role_name",column = "role_name"),
            @Result(property = "role_desc",column = "role_desc"),
            @Result(property = "role_status",column = "role_status"),
            @Result(property = "role_createtime",column = "role_createtime"),
            @Result(property = "role_modiftime",column = "role_modiftime"),
            @Result(property = "role_type",column = "role_type")
    })
    List<Role> getSelectRole(String role_name);


    //根据id查询角色信息
    @Select("select * from t_role where id = #{roleid} ")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "role_name",column = "role_name"),
            @Result(property = "role_desc",column = "role_desc"),
            @Result(property = "role_status",column = "role_status"),
            @Result(property = "role_createtime",column = "role_createtime"),
            @Result(property = "role_modiftime",column = "role_modiftime"),
            @Result(property = "role_type",column = "role_type")
    })
    Role selectidrole(int roleid);

    @Insert("insert into t_role(role_name,role_desc,role_status,role_createtime,role_modiftime,role_type) values(#{role_name},#{role_desc},0,now(),now(),#{role_type}) ")
    int AddRole(String role_name, String role_desc, int role_type);


    @Delete("delete from t_role  where id=#{id}")
    int DelRole(int id);


    @Update("update t_role set role_name=#{role_name},role_desc=#{role_desc},role_modiftime=now(),role_type=#{role_type} where id=#{id}")
    int UpdRole(int id, String role_name, String role_desc, int role_type);



    //停用角色
    @Update("update t_role set role_status=1 where id=#{roleid}")
    int offrole(int roleid);

    //启用角色
    @Update("update t_role set role_status=0 where id=#{roleid}")
    int onrole(int roleid);

}
